home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / d.t.p / utils / propage / donsgenies / donsgenies.lha / Don'sGenies / StyleTagsCreateSingle.pprx < prev    next >
Text File  |  1993-05-25  |  23KB  |  581 lines

  1. /* This genie creates a new style tag automatically by examining a block of selected text in a document. If the text is in a style which does not match an existing tag, a new tag is created and the text is optionally set to that tag. Tags are named with a simplified description of the typeface; you can alter any of these names to anything you wish (using the "Style Tags Modify" menu item). If you modify the tag, its typeface name might no longer suit it. */
  2.  
  3. /* Method: load in typographic data from selected text. If an existing style is used, see if it is modified (further data after the style name). Ignore any data for text after the first letter. If no existing style is used, assemble the data and compare with all existing styles to see if there is a match. If not, suggest a name for a new style, create it and apply it to the block. */
  4. /* Written by Don Cox 1993. Not Public Domain. All rights reserved. */
  5.  
  6. trace n
  7. if ~show(l, "gdarexxsupport.library") then
  8.     if ~(exists("libs:gdarexxsupport.library") & addlib("gdarexxsupport.library", 0, -30)) then
  9.         exit_msg("Please install the gdarexxsupport.library in your libs: directory before running this Genie")
  10.     
  11.  
  12. address command
  13.  
  14. text = ppm_GetBlockText( 1)
  15.  
  16. if text  = '' then exit_msg("No text selected")
  17. apply = ppm_Inform(2,"Apply style to whole of selected text?","No","Yes")
  18. call ppm_ShowStatus("  Analysing text...")
  19.  
  20. call clearcodes
  21.  
  22.  
  23. position = 1
  24.  
  25. change = 0
  26. position = parsecodes(position) /* parse a block of codes in text */
  27. if position = 0 then exit_msg("No style information found")
  28.  
  29. suggestname=stylename
  30. if change = 1 then do
  31.  
  32. /* put together style definition from text */
  33.     trackstring = "\t<"tracking">"
  34.     if tracking = "" then trackstring = ""
  35.     linespacestring = "\"linespacecode"<"||linespace||">"
  36.     if linespacecode = "" | linespacecode = "" then linespacestring = ""
  37.     fontnamestring = "\ff<"fontname">"
  38.     if fontname = "" then fontnamestring = ""
  39.     fontsizestring = "\fs<"fontsize">"
  40.     if fontsize = "" then fontsizestring = ""
  41.     colourstring = "\c<"colour">"
  42.     if colour = "" then colourstring = ""
  43.     fillpatternstring = "\FP<"fillpattern">"
  44.     if fillpattern = "" then fillpatternstring = ""
  45.     if fillpattern = "\Fp" then fillpatternstring = "\Fp"
  46.  
  47.     styledefinition = "\"paracode||paraname ||typestyle ||bold ||italic ||outline ||underline ||shadow ||superscript ||subscript || fontnamestring|| fontsizestring|| justification|| kerning|| hyphenation|| linespacestring|| trackstring||colourstring ||fillpatternstring
  48.                 
  49.  
  50.  
  51. /* see if new definition matches any of the old ones */
  52.     stylelist = ppm_GetStyleTagList()
  53.     stylelistTest = stylelist||"0a"x
  54.     parse var stylelist NumberOfTags "0a"x stylelist
  55.     tagchange = 1
  56.  
  57.     if NumberOfTags~=0 then do
  58.         do t=1 to NumberOfTags
  59.             parse var stylelist thisname "0a"x stylelist
  60.             thisdata = ppm_GetStyleTagData(thisname)
  61.             thisdata = substr(thisdata, pos("{",thisdata)+1)
  62.             thisdata = left(thisdata, lastpos("}",thisdata)-1)
  63.             if thisdata = styledefinition then do
  64.                 ThisTagName = "\dS<"||thisname||">"
  65.                 tagchange = 0 
  66.                 suggestname = thisname
  67.                 leave t
  68.                 end
  69.             end   /* t=1 to NumberOfTags  */
  70.     end
  71.     
  72. if tagchange ~=0 then do
  73.     
  74.     numbering = 1
  75.     newbold = ""
  76.     if right(bold,1) = "B" then newbold = "B"
  77.     newitalic = ""
  78.     if right(italic,1) = "I" then newitalic = "I"
  79.     suggestname = left(fontname, 9)||newbold||newitalic||"."||(fontsize%1)||"pt."||colour
  80.     testsuggest = "0a"x||suggestname||"0a"x
  81.     
  82.     do i = 1 to 999  /* if name already used, give it a new number */
  83.         if pos(testsuggest,stylelistTest)=0 then break
  84.         numbering = numbering+1
  85.         suggestname = left(fontname, 9)||newbold||newitalic||"."||(fontsize%1)||"pt."||colour"."||right(numbering, 3,"0")
  86.         testsuggest = "0a"x||suggestname||"0a"x
  87.         end
  88.  
  89. do i=1 to 10
  90.     newname = ppm_GetForm(" Name of new style tag",30," Suggested Name :"suggestname)
  91.     if newname = "" then exit_msg("User aborted genie")
  92.     newtest = "0a"x||newname||"0a"x  /* test for complete lines only */
  93.     if pos(newtest,stylelistTest)=0 then do
  94.         styledefinition = "<"newname"{"styledefinition"}>"
  95.         call ppm_DefineStyleTag(styledefinition)
  96.         call ppm_SetStyleTag(newname)
  97.         call exit_msg
  98.         end
  99.  
  100.     choice = ppm_inform(3,"Replace existing tag of same name?","Replace","Try another name","Cancel")
  101.     if choice = 2 then exit_msg("Aborted by User")
  102.     if choice = 0 then do
  103.         styledefinition = "<"newname"{"styledefinition"}>"
  104.         call ppm_DefineStyleTag(styledefinition)
  105.         call ppm_SetStyleTag(newname)
  106.         call exit_msg
  107.         end       
  108.     styledefinition = "<"newname"{"styledefinition"}>"
  109.     call ppm_DefineStyleTag(styledefinition)      
  110. end  /* i=1 to 10  */
  111. end  /* tagchange~=0  */
  112.  
  113.  
  114. if apply = 1 then call ppm_SetStyleTag(suggestname)
  115.  
  116. if tagchange = 0 & apply = 1 then do
  117.     call exit_msg('Applying existing tag "'suggestname'" to text block.')
  118.     end
  119. if tagchange = 0 then do
  120.     call exit_msg('This is existing tag "'suggestname'".')
  121.     end
  122. call exit_msg()
  123. end
  124.  
  125. /*  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  */
  126.  
  127. /* Parse a block of style codes in text; stop at first text character  */
  128.  
  129. parsecodes:
  130. parse arg position
  131. position = pos("\",text,position)
  132. if position = 0 then return position
  133. if substr(text,position+1,1) = "." then position = 0 /* end of text */
  134. if position = 0 then return position
  135. nonstylecode = ""
  136. stylecode = "ds"  /* assume new block of codes means new style */
  137.  
  138.         do forever
  139.             if substr(text,position,1)~="\" then break
  140.             if substr(text,position+1,1) = "." then position = -1
  141.             if position = -1 then break
  142.             code = substr(text,position+1,2)
  143.             select
  144.                 when verify(left(code,1),"pNMPTs-!?#","m")~=0 then call parsenonstylecodes
  145.                  
  146.                 when code = "dp" then do
  147.                     paraname = ""
  148.                     paracode = code
  149.                     position = position+3
  150.                     end
  151.                 when code = "dP" then do
  152.                     position1 = pos(">",text,position)
  153.                     position = position+4
  154.                     oldname = paraname
  155.                     paraname = "<"||substr(text, position, position1-position)||">"
  156.                     if paraname~=oldname  then change = 1
  157.                     oldname = paracode
  158.                     paracode = "dP"
  159.                     if paracode~=oldname  then change = 1
  160.                     position = position1+1
  161.                     end
  162.                 when code = "ds" then do
  163.                     stylename = ""
  164.                     stylecode = code
  165.                     position = position+3
  166.                     end
  167.                 when code = "dS" then do
  168.                     position1 = pos(">",text,position)
  169.                     position = position+4
  170.                     stylename = substr(text,position,position1-position)
  171.                     tagdata = ppm_GetStyleTagData(stylename)
  172.                     call parsetag(tagdata) /* new style so reset all variables  */
  173.                     change = 0
  174.                     stylecode = "dS"
  175.                     position = position1+1
  176.                     end
  177.                 when verify(left(code,1),"bB","m")~=0 then do
  178.                     oldname = bold
  179.                     bold = "\"||left(code,1)
  180.                     position = position+2
  181.                     if bold~=oldname  then change = 1
  182.                     end
  183.                 when verify(left(code,1),"iI","m")~=0 then do
  184.                     oldname = italic
  185.                     italic = "\"||left(code,1)
  186.                     position = position+2
  187.                     if italic~=oldname  then change = 1
  188.                     end
  189.                 when verify(left(code,1),"uU","m")~=0 then do
  190.                     oldname = underline
  191.                     underline = "\"||left(code,1)
  192.                     position = position+2
  193.                     if underline~=oldname  then chang